home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.StyleChat / EventLoop.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-18  |  3.6 KB  |  135 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        EventLoop.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.protos.h"        /* Get the prototypes for application.            */
  27.  
  28.  
  29.  
  30. /*****************************************************************************/
  31.  
  32.  
  33.  
  34. extern RgnHandle    gCursorRgn;                /* DTS.Lib..framework global. */
  35.     /* The current cursor region.  The initial cursor region is an empty region,
  36.     ** which will cause WaitNextEvent to generate a mouse-moved event, which will
  37.     ** cause us to set the cursor for the first time. */
  38.  
  39. extern Boolean        gQuitApplication;        /* DTS.Lib..framework global. */
  40.     /* This is set to false by Initialize.  When the user selects Quit
  41.     ** (and does not abort the quit), then this boolean is set true. */
  42.  
  43. Boolean        gLowOnMem;
  44. static void    ManageLowMem(void);
  45.  
  46. #define kRamReserve 0x10000L
  47. #define kRamSlop    0x08000L
  48.  
  49.  
  50.  
  51. /*****************************************************************************/
  52. /*****************************************************************************/
  53.  
  54.  
  55.  
  56. /* Get events forever, and handle them by calling DoEvent.  Get the events by
  57. ** calling WaitNextEvent. */
  58.  
  59. #pragma segment Main
  60. void    EventLoop(void)
  61. {
  62.     EventRecord        event;
  63.  
  64.     while (!gQuitApplication) {
  65.         ManageLowMem();
  66.         if (!WaitNextEvent(everyEvent, &event, 15, gCursorRgn))
  67.             event.what = nullEvent;
  68.         DoEvent(&event);
  69.     };
  70. }
  71.  
  72.  
  73.  
  74. /*****************************************************************************/
  75.  
  76.  
  77.  
  78. /* This is called to determine if there is enough ram available for various
  79. ** application operations.  Typically, if there is not enough, certain menu
  80. ** items are dimmed, thus preventing further use of memory. */
  81.  
  82. #pragma segment Main
  83. static void    ManageLowMem(void)
  84. {
  85.     static Handle    reserveMemHndl;
  86.  
  87.     if (!reserveMemHndl) {
  88.         reserveMemHndl = NewHandle(0);
  89.         EmptyHandle(reserveMemHndl);
  90.     }
  91.  
  92.     if (gLowOnMem) {
  93.         ReallocateHandle(reserveMemHndl, kRamReserve + kRamSlop);
  94.         if (*reserveMemHndl) {
  95.             SetHandleSize(reserveMemHndl, kRamReserve);
  96.             HPurge(reserveMemHndl);
  97.             gLowOnMem = false;
  98.         }
  99.     }
  100.     else {
  101.         if (!*reserveMemHndl) {
  102.             ReallocateHandle(reserveMemHndl, kRamReserve);
  103.             if (*reserveMemHndl) HPurge(reserveMemHndl);
  104.             else {
  105.                 NewDocumentWindow(nil, 'LMEM', false);
  106.                 gLowOnMem = true;
  107.             }
  108.         }
  109.     }
  110. }
  111.  
  112.  
  113.  
  114. /*****************************************************************************/
  115. /*****************************************************************************/
  116. /*****************************************************************************/
  117.  
  118.  
  119.  
  120. /* •• Called by DTS.Lib..framework. •• */
  121.  
  122. /* Handle the cursor changes.  Most of the work is done by the application
  123. ** framework.  Each window has its own cursor calculation proc, so you
  124. ** shouldn't have to add any code here.  You may wish to do some special
  125. ** stuff prior to the DoWindowCursor call if you have modeless dialogs. */
  126.  
  127. #pragma segment Main
  128. void    DoCursor(void)
  129. {
  130.     DoWindowCursor();
  131. }
  132.  
  133.  
  134.  
  135.